
let ul=document.querySelector('.main ul')
let re=document.querySelector('.return')
console.log(localStorage.getItem('brandtitleid'));
let xhr =new XMLHttpRequest()
xhr.open('get',`http://chst.vip:1234/api/getbrandproductlist?brandtitleid=${localStorage.getItem('brandtitleid')}`,true)
xhr.onload=function(){
    if(xhr.status===200){
        let res =JSON.parse(xhr.responseText)
        let an=res .result
        let lis=''
        let las
        an.forEach(item => {
            lis+=`
            <li productId=${item.productId} brandName=${item.brandName} categoryId=${item.categoryId}>
            ${item.productImg}
            <div class="zi">
                <p>${item.productName}</p>
                <p>${item.productPrice}</p>
                <p>${item.productQuote}</p>
                <i class="iconfont icon-xinxi">${item.productCom}</i>
            </div>
            </li>
            `
        });
        ul.innerHTML=lis
    }
}
xhr.send(null)

let xhr1 =new XMLHttpRequest()
xhr1.open('get',`http://chst.vip:1234/api/getbrandproductlist?brandtitleid=${localStorage.getItem('brandtitleid')}`,true)
xhr1.onload=function(){
    if(xhr1.status===200){
        let res =JSON.parse(xhr1.responseText)
        let an=res .result
        let lis=''
        an.forEach(item => {
            lis=`
            <a href="">首页></a>
            <a href="">全部分类></a>
            <a href="">${localStorage.getItem('brandName')}</a>
            <p>筛选</p>
            `
            re.innerHTML=lis
        });
       
    }
}
xhr1.send(null)


ul.onclick=function(e){
    var e = e || window.event;
    var target = e.target || e.srcElement;
    if(target.nodeName==='IMG' || target.nodeName==='DIV'){
        localStorage.setItem('productid',target.parentNode.getAttribute('productId'))
        localStorage.setItem('categoryId',target.parentNode.getAttribute('categoryId'))
        localStorage.setItem('brandName1',target.parentNode.getAttribute('brandName'))
        location.href = 'http://127.0.0.1:5500/js/day18/html/buy.html';
    }else {
        localStorage.setItem('productid',target.parentNode.parentNode.getAttribute('productId'))
        localStorage.setItem('categoryId',target.parentNode.parentNode.getAttribute('categoryId'))
        localStorage.setItem('brandName1',target.parentNode.parentNode.getAttribute('brandName'))
        location.href = 'http://127.0.0.1:5500/js/day18/html/buy.html';
    }
}